<?php
class ShenbaoAction extends Action {
	public function index() {
		$this->display ();
	}
	public function insert() {
		// 保存表单数据 包括附件数据
		$action=$this->_post("action");
		if($action=="grj"){
			$User=D("Grj"); // 实例化User对象
		}else if($action=="zzj"){
			$User=D("Zzj"); // 实例化User对象
		}else if($action=="xmj"){
			$User=D("Xmj"); // 实例化User对象
		}
		if ($User->create()) {
			$User->ctime=Date("y-m-d H:i:s");
			if($User->add ()){ // 写入用户数据到数据库
				$this->success ( "数据保存成功！" );
			}else{
				$this->error("数据保存失败!");
			}
		}else {
            $this->error($User->getError());
        }
	}
	
	public function upload(){
		if(!empty($_FILES)){
		import ( "ORG.Net.UploadFile" );
		$upload = new UploadFile (); // 实例化上传类
		$upload->maxSize=2048000; // 设置附件上传大小
		$upload->allowExts=array('jpg','gif','png','jpeg','doc','docx'); // 设置附件上传类型
		$upload->savePath='./Public/Uploads/j/'; // 设置附件上传目录
		$upload->saveRule=uniqid;
		if (!$upload->upload()){ // 上传错误提示错误信息
			$this->ajaxReturn($upload->getErrorMsg(),"上传失败",0);
		} else {// 上传成功 获取上传文件信息
			$info=$upload->getUploadFileInfo();
			$this->ajaxReturn($info[0]["savename"],"上传成功",1);
		}
		}else{
			$this->ajaxReturn("没有选择任何文件","上传失败",3);
		}
	}
}